using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace VoliaStat
{
    public partial class MyDoublePie : UserControl
    {
        public MyDoublePie()
        {
            InitializeComponent();

            _rectangle1 = new Rectangle(this.ClientRectangle.Location,this.ClientRectangle.Size);

            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            BackColor = Color.Transparent;
            
        }

        Rectangle _rectangle1;
        Rectangle _rectangle2;
        Rectangle _rectangle3;


        const int MARGIN = 1;

        int _persentDay=0;
        int _persentTraff=0;
        int _persentTraffToday=0;
        int _persentTimer=0;



        public void SetPersent(int persent1,int persent2,int persent3)
        {
            _persentDay = persent1;
            _persentTraff = persent2;
            _persentTraffToday = persent3;
            this.Refresh();
        }

        public void SetPersentTimer(int persent)
        {
            _persentTimer = persent;
            this.Refresh();
        }

        private void MyDoublePie_Paint(object sender, PaintEventArgs e)
        {

            Graphics g =  e.Graphics;
            if (_persentTimer!=0) 
            {   
                int  p = 360*_persentTimer/100;
                g.FillPie(Brushes.White, _rectangle3,270+p,360-p);
            } else
            {
                g.FillEllipse(Brushes.White,_rectangle3);
            }
            
            g.FillEllipse(Brushes.Yellow,_rectangle1);

            if (_persentDay!=0) g.FillPie(Brushes.GreenYellow,_rectangle1,270,360*_persentDay/100);
            

            if (_persentTraff!=0) 
            {
                if (_persentTraff>=100)
                {
                    g.FillEllipse(Brushes.Red, _rectangle2);
                } else
                {
                    int p = 360*_persentTraff/100;
                    if (_persentTraffToday!=0)
                    {   int pt = 360*_persentTraffToday/100;
                        g.FillPie(Brushes.DarkRed, _rectangle2,270,p);
                        g.FillPie(Brushes.Red, _rectangle2,270,p-pt);

                    
                    } else
                    {
                        g.FillPie(Brushes.Red, _rectangle2,270,p);
                    }
                }
            }


        }

        private void MyDoublePie_Load(object sender, EventArgs e)
        {
            _rectangle3 = new Rectangle(this.ClientRectangle.Location,this.ClientRectangle.Size);
            _rectangle3.Height -= MARGIN;
            _rectangle3.Width -= MARGIN;
            int N = this.ClientRectangle.Height / 12;
            _rectangle1 = new Rectangle(_rectangle3.Location,_rectangle3.Size);
            _rectangle1.Height -= N*2;
            _rectangle1.Width -= N*2;
            _rectangle1.X+=N;
            _rectangle1.Y+=N;
            N = this.ClientRectangle.Height / 6;
            _rectangle2 = new Rectangle(_rectangle3.Location,_rectangle3.Size);
            _rectangle2.Height -= N*2;
            _rectangle2.Width -= N*2;
            _rectangle2.X+=N;
            _rectangle2.Y+=N;
           
            
            


        }
    }
}

